package 行为型模式.状态模式.before;

public class Lift implements ILift {
    //声明一个记录当前电梯状态
    private int state;

    @Override
    public void setState(int state) {
        this.state = state;
    }

    @Override
    public void open() {
        switch (state) {
            case OPENING_STATE:
                //什么事都不做
                break;
            case CLOSING_STATE:
            case STOPPING_STATE:
                System.out.println("电梯打开了");
                //设置当前电梯状态为开启
                setState(OPENING_STATE);
                break;
            case RUNNING_STATE:
                break;
            //设置当前电梯状态为开启
        }
    }

    @Override
    public void close() {
        switch (state) {
            case OPENING_STATE:
                System.out.println("电梯关闭了");
                setState(CLOSING_STATE);
                break;
            case CLOSING_STATE:
            case RUNNING_STATE:
            case STOPPING_STATE:
                break;
        }
    }

    @Override
    public void run() {
        switch (state) {
            case OPENING_STATE:
            case RUNNING_STATE:
                break;
            case CLOSING_STATE:
            case STOPPING_STATE:
                System.out.println("电梯开始运行了");
                setState(RUNNING_STATE);
                break;
        }
    }

    @Override
    public void stop() {
        switch (state) {
            case OPENING_STATE:
                //开门的电梯处于停止状态，什么事都不做
                break;
            case CLOSING_STATE:
            case RUNNING_STATE:
                System.out.println("电梯停止了");
                //设置当前电梯状态为开启
                setState(STOPPING_STATE);
                break;
            //设置当前电梯状态为开启
            case STOPPING_STATE:
                break;
        }
    }
}
